package com.kayang.dd.service;



import com.kayang.common.HttpResilience4jCommand;
import com.kayang.common.aop.IService;
import com.kayang.common.aop.SPEnable;
import com.kayang.dd.pojo.DDcontext;
import com.kayang.dd.pojo.UserModel;
import com.kayang.dd.pojo.param.ListUserByDeptParam;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserService implements IService {

    @Override
    public String getBeforeSp() {
        // 参数{String json}  json请求信息，请求后包含响应。
        return "TSP_Before_DDUserEdit";
    }

    @Override
    public String getAfterSp() {
        // 参数{String json}   json请求信息，请求后包含响应。
        return "TSP_After_DDUserEdit";
    }


    @SPEnable
    public Map creatUser(UserModel userModel, DDcontext context){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), userModel.toMap(userModel));
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);

        return ret;
    }

    @SPEnable
    public Map updateUser(UserModel userModel, DDcontext context){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), userModel.toMap(userModel));
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);

        return ret;
    }


    @SPEnable
    public Map deleteUser(Map param, DDcontext context){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), param);
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);

        return ret;
    }


    @SPEnable
    public Map getUser(Map param, DDcontext context){
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), param);
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);
        return ret;
    }


    @SPEnable
    public Map getUserByDept(ListUserByDeptParam deptParam, DDcontext context) {
        HttpResilience4jCommand httpResilience4jCommand = new HttpResilience4jCommand(context.getUrl(), context.getMethod(), deptParam.toMap(deptParam));
        Map ret = httpResilience4jCommand.execute();
        context.setRespbody(ret);
        return ret;
    }
}
